package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.mapper.NewsCommentMapper;
import cn.wolfcode.trip.base.service.INewsCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewsCommentServiceImpl implements INewsCommentService {

    @Autowired
    private NewsCommentMapper newsCommentMapper;

    @Override
    public void save(Long userId, String content, Long newsId) {
        NewsComment entity = new NewsComment();
        if (content != null && content.trim().length() > 0) {
            entity.setContent(content);
        }
        entity.setCreateTime(new Date());
        entity.setUserId(userId);
        entity.setNewsId(newsId);
        newsCommentMapper.insert(entity);
    }

    @Override
    public List<NewsComment> selectByNewsId(Long newsId) {
        return newsCommentMapper.selectByNewsId(newsId);
    }
}
